package cn.swu.ws;
import java.sql.*;

public class demo1 {
    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        String dburl="jdbc:mysql://localhost:3306/bookstore";
        String dbuser="root";
        String dbpassword="admin";
        Class.forName("com.mysql.cj.jdbc.Driver");
        try (Connection connection = DriverManager.getConnection(dburl,dbuser,dbpassword);){
            try(Statement statement = connection.createStatement()){
                String sql="select * from book";
                try(ResultSet resultSet = statement.executeQuery(sql)){
                    while (resultSet.next()){
                        int id= resultSet.getInt("id");
                        String name= resultSet.getString("name");
                        String author = resultSet.getString("author");
                        float price = resultSet.getFloat("price");
                        String content = resultSet.getString("content");
                        System.out.println(id+" "+name+" "+author+" "+price+" "+content);
                    }
                }
            }
        }
    }
}
